package com.gmail.shazi199.gauth;

import java.util.Timer;
import java.util.TimerTask;

// read ~/.google-authenticator
// display counter with dots (30 second refresh)
// jcuff@srv:~/auth/javaauth/jc$ java -classpath ./ Authenticator.Main /home/jcuff/.google_authenticator 

public class Main {
	Timer timer;

	public static void main(String[] args) {
		System.out.println("\nAuthenticator Started!");
		System.out.println(":----------------------------:--------:");
		System.out.println(":       Code Wait Time       :  Code  :");
		System.out.println(":----------------------------:--------:");
		Main main = new Main();
		main.reminder("aaaaa");
	}

	public void reminder(String secret) {
		timer = new Timer();
		timer.scheduleAtFixedRate(new TimedPin(secret), 0, 1 * 1000);
	}

	int count = 1;

	class TimedPin extends TimerTask {
		private String secret;
		private GAuth auth;

		public TimedPin(String secret) {
			this.secret = secret;
			this.auth = new GAuth();
		}

		String previouscode = "";

		public void run() {
			String newout = auth.computePin(secret, null);
			if (previouscode.equals(newout)) {
				System.out.print(".");
			} else {
				if (count <= 30) {
					for (int i = count + 1; i <= 30; i++) {
						System.out.print("+");
					}
				}
				System.out.println(": " + newout + " :");
				count = 0;
			}
			previouscode = newout;
			count++;
		}
	}
}
